package com.umeox.watch.prayertime.base;

import android.annotation.SuppressLint;
import android.content.Intent;

import androidx.multidex.MultiDexApplication;

import com.tencent.mmkv.MMKV;
import com.umeox.moto.common.log.Logger;
import com.umeox.watch.moto.dataservice.DataProvider;
import com.umeox.watch.moto.dataservice.constants.Constants;
import com.umeox.watch.prayertime.R;
import com.umeox.watch.prayertime.receiver.AlarmReceiver;

import uk.co.chrisjenx.calligraphy.CalligraphyConfig;


public class BaseApp extends MultiDexApplication {

    private static BaseApp instance;
    private MMKV mmkv;

    @SuppressLint("WrongConstant")
    public void schedulePrayerTimeAlarm() {
        Logger.i("发送广播重置闹钟");
        Intent intent = new Intent(AlarmReceiver.ACTION_UPDATED_ALARMLIST);
        intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES | Intent.FLAG_RECEIVER_FOREGROUND | Constants.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcast(intent);
    }

    public MMKV getMmkv() {
        if (mmkv == null) {
            mmkv = MMKV.defaultMMKV();
        }
        return mmkv;
    }

    public static BaseApp getInstance() {
        return instance;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        DataProvider.initialize(this);
        MMKV.initialize(this);
        Logger.i("=============BaseApp onCreate============");
        schedulePrayerTimeAlarm();
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/Roboto-Medium.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build()
        );
    }
}
